<?php
include_once '../Login/databaseconnection.php';

   $_SESSION['Comp_Id']=$_SESSION['Competition_Id'];
   $_SESSION['Sch_Id']=$_SESSION['School_Id'];
   $_SESSION['Dat']=$_SESSION['Date'];
    $Competition_Id=$_SESSION['Competition_Id'];
    $School_Id=$_SESSION['School_Id'];
	$Date=$_SESSION['Date'];
    $Competition_Id1=$_POST['Competition_Id'];
    $School_Id1=$_POST['School_Id'];
    $No_Of_Students=$_POST['No_Of_Students'];
    $No_Of_Teachers=$_POST['No_Of_Teachers'];
   $Result=$_POST['Result'];
    $Date1=$_POST['Date'];
    $Scope=$_POST['Scope'];
    $Winner=$_POST['Winner'];
   date_default_timezone_set("Europe/Paris");
    $t_d=date("Y/m/d");
	
   if($Competition_Id1==""||$School_Id1==""||$No_Of_Students==""||$No_Of_Teachers==""||$Result==""||$Date1==""||$Scope=="")
	{
		  $_SESSION['errorin']="Please check your inputs!";	 
	}
	else
	{
if($Result=="Win"&&$Winner=="")
{
$_SESSION['errornotallo']="Please enter the winner's name!";
	}
	else if($Result=="Win"&&$Winner!="")
	{
$sql=mysql_query("UPDATE competition SET Competition_Id='$Competition_Id1',School_Id='$School_Id1',No_Of_Students='$No_Of_Students',No_Of_Teachers='$No_Of_Teachers',Result='$Result',Date='$Date1',Scope='$Scope',Winner='$Winner',Last_Updated_Date='$t_d' WHERE Competition_Id='$Competition_Id' AND School_Id='$School_Id' AND Date='$Date'");
unset($_SESSION['Competition_Id']);
unset($_SESSION['School_Id']);
unset($_SESSION['Date']);
if(mysql_affected_rows()!=0)
  {
$_SESSION['error']="The record is successfully updated!";
  }

 if(mysql_affected_rows()==0)
  {
 $_SESSION['error']="Sorry unable to update this record!";
    }	
}
else if($Result=="Loss")
{
$sql=mysql_query("UPDATE competition SET Competition_Id='$Competition_Id1',School_Id='$School_Id1',No_Of_Students='$No_Of_Students',No_Of_Teachers='$No_Of_Teachers',Result='$Result',Date='$Date1',Scope='$Scope',Winner='',Last_Updated_Date='$t_d' WHERE Competition_Id='$Competition_Id' AND School_Id='$School_Id' AND Date='$Date'");
unset($_SESSION['Competition_Id']);
unset($_SESSION['School_Id']);
unset($_SESSION['Date']);
if(mysql_affected_rows()!=0)
  {
$_SESSION['error']="The record is successfully updated!";
  }

 if(mysql_affected_rows()==0)
  {
 $_SESSION['error']="Sorry unable to update this record!";
    }	
}	
}
  ?>
